import { WebGLRenderer, Color } from 'three'

interface RendererParams {
    canvas: HTMLCanvasElement,
    width?: number,
    height?: number,
    bgcolor?: string,
    bgalpha?: number
}

function createRenderer (params: RendererParams) : WebGLRenderer {
    const renderer = new WebGLRenderer({
        canvas: params.canvas,
        antialias: true,
        preserveDrawingBuffer: true,
        alpha: true
    })

    renderer.setPixelRatio(window.devicePixelRatio)
    renderer.setSize(params.width || 800, params.height || 600)
    renderer.setClearColor(new Color(params.bgcolor || '#2323e1'), Number(params.bgalpha || 1))
    renderer.shadowMap.enabled = true

    renderer.localClippingEnabled = true

    return renderer
}

export {
    createRenderer
}
